#include "TcpServer.hpp"
#include "Service.hpp"
#include "NetCal.hpp"
#include <memory>

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " serverport" << std::endl;
    }
    uint16_t serverport = std::stoi(argv[1]);

    // 应用层
    NetCal cal;
    // 表示层, 数据格式的转换
    IOService service(std::bind(&NetCal::Calculator, &cal, std::placeholders::_1));
    // 会话层, 连接的维护
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(serverport, 
            std::bind(&IOService::Excute, &service, std::placeholders::_1, std::placeholders::_2));
    tsvr->Loop();
    return 0;
}